﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlgoImpl
{
    [Serializable]
    public class Worker : IDataInTwoSideGraph
    {
        private string m_Name;
        private double m_Rank;
        private List<Shift> m_Shifts = new List<Shift>();
        private int m_MaxShiftsThatCanGive;


        private bool isShiftExist(string shift)
        {
            bool isExist = false;
            foreach (Shift _shift in m_Shifts)
            {
                if (_shift.Id.Equals(shift))
                {
                    isExist = true;
                    break;
                }
            }
            return isExist;
        }
        public void Clear()
        {
            m_Shifts.Clear();
            m_Rank = 0;
        }
        public List<string> GetAllShiftsIds()
        {
            List<string> shiftsIds = new List<string>();
            foreach (Shift shift in m_Shifts)
            {
                shiftsIds.Add(shift.Id);
            }
            return shiftsIds;
        }

        public void AddShift(string shift)
        {
            if (!isShiftExist(shift))
            {
                    m_Shifts.Add(SharedData.Instance.GetShiftById(shift));
            }
            else
            {
                //throw new Exception("shift " + shift + " exist");
            }
        }
        public bool IsRegisterdToShift(string shiftId)
        {
            return isShiftExist(shiftId);
        }

        //public List<Shift> Shifts 
        //{
        //    get { return m_Shifts; }
        //    set { m_Shifts = value; }
        //}
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }
        public double Rank
        {
            get { return m_Rank; }
            set { m_Rank = value; }
        }
        public int MaxShiftsThatCanGive
        {
            get { return m_MaxShiftsThatCanGive; }
            set { m_MaxShiftsThatCanGive = value; } 
        }
        public bool CanGiveMoreShifts()
        {
            return m_Shifts.Count < m_MaxShiftsThatCanGive;
        }
        public string Id { get; set; }

        public override bool Equals(object obj)
        {
            bool isEqual = false;
            if (typeof(Worker) == obj.GetType())
            {
                if ((obj as Worker).Id.Equals(Id))
                {
                    isEqual = true;
                }
            }
            return isEqual;
        }
        public override string ToString()
        {
            return string.Format("{0} {1} ", m_Name, Id.ToString());
        }
       
    }
}
